<html lang="zh-CN"><head><meta charset="UTF-8"><style>.nodata  main {width:1000px;margin: auto;}</style></head><body class="nodata " style=""><div class="main_father clearfix d-flex justify-content-center " style="height:100%;"> <div class="container clearfix " id="mainBox"><main><div class="blog-content-box">
<div class="article-header-box">
<div class="article-header">
<div class="article-title-box">
<h1 class="title-article" id="articleContentId">(B卷,100分)- 组成最大数（Java & JS & Python & C）</h1>
</div>
</div>
</div>
<div id="blogHuaweiyunAdvert"></div>

        <div id="article_content" class="article_content clearfix">
        <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/kdoc_html_views-1a98987dfd.css">
        <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-044f2cf1dc.css">
                <div id="content_views" class="htmledit_views">
                    <h4 id="main-toc">题目描述</h4> 
<p>小组中每位都有一张卡片&#xff0c;卡片上是6位内的正整数&#xff0c;将卡片连起来可以组成多种数字&#xff0c;计算组成的最大数字。</p> 
<p></p> 
<h4 id="%E8%BE%93%E5%85%A5%E6%8F%8F%E8%BF%B0">输入描述</h4> 
<p>“,”号分割的多个正整数字符串&#xff0c;不需要考虑非数字异常情况&#xff0c;小组最多25个人。</p> 
<p></p> 
<h4 id="%E8%BE%93%E5%87%BA%E6%8F%8F%E8%BF%B0">输出描述</h4> 
<p>最大的数字字符串</p> 
<p></p> 
<h4 id="%E7%94%A8%E4%BE%8B">用例</h4> 
<table border="1" cellpadding="1" cellspacing="1" style="width:500px;"><tbody><tr><td style="width:113px;">输入</td><td style="width:385px;">22,221</td></tr><tr><td style="width:113px;">输出</td><td style="width:385px;">22221</td></tr><tr><td style="width:113px;">说明</td><td style="width:385px;">无</td></tr></tbody></table> 
<table border="1" cellpadding="1" cellspacing="1" style="width:500px;"><tbody><tr><td>输入</td><td>4589,101,41425,9999</td></tr><tr><td>输出</td><td>9999458941425101</td></tr><tr><td>说明</td><td>无</td></tr></tbody></table> 
<h4 id="%E9%A2%98%E7%9B%AE%E8%A7%A3%E6%9E%90">题目解析</h4> 
<p>题解请看<a href="https://blog.csdn.net/qfc_128220/article/details/127418118?spm&#61;1001.2014.3001.5501" title="华为OD机试 - 数组组成的最小数字_伏城之外的博客-CSDN博客">华为OD机试 - 数组组成的最小数字_伏城之外的博客-CSDN博客</a></p> 
<p>增加一个测试用例</p> 
<blockquote> 
 <p>3,32,321</p> 
</blockquote> 
<p></p> 
<h4 id="%E7%AE%97%E6%B3%95%E6%BA%90%E7%A0%81">JavaScript算法源码</h4> 
<pre><code class="language-javascript">/* JavaScript Node ACM模式 控制台输入获取 */
const readline &#61; require(&#34;readline&#34;);

const rl &#61; readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

rl.on(&#34;line&#34;, (line) &#61;&gt; {
  const arr &#61; line.split(&#34;,&#34;);

  arr.sort((a, b) &#61;&gt; {
    const s1 &#61; a &#43; b;
    const s2 &#61; b &#43; a;
    return s1 &#61;&#61; s2 ? 0 : s1 &gt; s2 ? -1 : 1;
  });

  console.log(arr.join(&#34;&#34;));
});
</code></pre> 
<p></p> 
<h4>Java算法源码</h4> 
<pre><code class="language-java">import java.util.Arrays;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc &#61; new Scanner(System.in);
    String[] arr &#61; sc.next().split(&#34;,&#34;);
    Arrays.sort(arr, (a, b) -&gt; (b &#43; a).compareTo(a &#43; b));

    StringBuilder sb &#61; new StringBuilder();
    for (String s : arr) sb.append(s);
    System.out.println(sb);
  }
}
</code></pre> 
<p></p> 
<h4>Python算法源码 </h4> 
<pre><code class="language-python">import functools

# 输入获取
arr &#61; input().split(&#34;,&#34;)


# 排序规则
def cmp(a, b):
    s1 &#61; a &#43; b
    s2 &#61; b &#43; a
    return 0 if s1 &#61;&#61; s2 else -1 if s1 &gt; s2 else 1


# 算法入口
def getResult(arr):
    arr.sort(key&#61;functools.cmp_to_key(cmp))
    return &#34;&#34;.join(arr)


# 算法调用
print(getResult(arr))
</code></pre> 
<p></p> 
<h4>C算法源码</h4> 
<pre><code class="language-cpp">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

#define MAX_SIZE 25

int cmp(const void* a, const void* b) {
    char* A &#61; *((char**) a);
    char* B &#61; *((char**) b);

    char AB[10000] &#61; {&#39;\0&#39;};
    strcat(AB, A);
    strcat(AB, B);

    char BA[10000] &#61; {&#39;\0&#39;};
    strcat(BA, B);
    strcat(BA, A);

    return strcmp(BA, AB);
}

int main() {
    char line[10000];
    gets(line);

    char* ss[MAX_SIZE];
    int ss_size &#61; 0;

    char* token &#61; strtok(line, &#34;,&#34;);
    while(token !&#61; NULL) {
        ss[ss_size&#43;&#43;] &#61; token;
        token &#61; strtok(NULL, &#34;,&#34;);
    }

    qsort(ss, ss_size, sizeof(char*), cmp);

    char res[10000];
    for(int i&#61;0; i&lt;ss_size; i&#43;&#43;) {
        strcat(res, ss[i]);
    }

    puts(res);

    return 0;
}</code></pre> 
<p> </p>
                </div>
        </div>
        <div id="treeSkill"></div>
        <div id="blogExtensionBox" style="width:400px;margin:auto;margin-top:12px" class="blog-extension-box"></div>
    <script>
  $(function() {
    setTimeout(function () {
      var mathcodeList = document.querySelectorAll('.htmledit_views img.mathcode');
      if (mathcodeList.length > 0) {
        for (let i = 0; i < mathcodeList.length; i++) {
          if (mathcodeList[i].naturalWidth === 0 || mathcodeList[i].naturalHeight === 0) {
            var alt = mathcodeList[i].alt;
            alt = '\\(' + alt + '\\)';
            var curSpan = $('<span class="img-codecogs"></span>');
            curSpan.text(alt);
            $(mathcodeList[i]).before(curSpan);
            $(mathcodeList[i]).remove();
          }
        }
        MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
      }
    }, 1000)
  });
</script>
</div></html>